package org.nfyszny.zzzs.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.system.vo.LoginUser;
import org.nfyszny.zzzs.modules.entity.ZzzsBasicInfo;
import org.nfyszny.zzzs.modules.mapper.ZzzsBasicInfoMapper;
import org.nfyszny.zzzs.modules.service.IZzzsBasicInfoService;
import org.nfyszny.zzzs.modules.utils.UserUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 基本信息
 * @Author: jeecg-boot
 * @Date: 2022-11-10
 * @Version: V1.0
 */
@Service
public class ZzzsBasicInfoServiceImpl extends ServiceImpl<ZzzsBasicInfoMapper, ZzzsBasicInfo> implements IZzzsBasicInfoService {

    @Override
    public void updateIntroduceStatus(String id, Integer status) {
        ZzzsBasicInfo zzzsBasicInfo = new ZzzsBasicInfo();
        zzzsBasicInfo.setId(id);
        zzzsBasicInfo.setState(status);
        baseMapper.updateById(zzzsBasicInfo);

    }

    @Override
    public IPage<ZzzsBasicInfo> pageList(Page<ZzzsBasicInfo> page, QueryWrapper<ZzzsBasicInfo> queryWrapper) {
        LoginUser userInfo = UserUtils.getUserInfo();
        queryWrapper.eq("sys_org_code", userInfo.getOrgCode());

        Page<ZzzsBasicInfo> pageList = this.page(page, queryWrapper);
        List<ZzzsBasicInfo> records = pageList.getRecords();
        //根据state变成boolean类型值方便页面渲染
        pageList.setRecords(records.stream().map(item -> {
            item.setStateBoolean(item.getState() == 1);
            return item;
        }).collect(Collectors.toList()));
        return pageList;
    }
}
